/*
 * Project Name: cms_web
 * File Name: DownPageAction.java
 * Copyright: ZKTeco Corporation 2015
 * Description: TODO 请在此处添加对本文件的描述
 * Creator: Administrator
 * Create Date: 2015年3月19日 上午9:51:13
 */
package com.shishuo.cms.action.manage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cms.auth.AuthPassport;
import com.shishuo.cms.entity.ClassesEntity;
import com.shishuo.cms.entity.DownPageEntity;
import com.shishuo.cms.entity.VideoEntity;
import com.shishuo.cms.entity.vo.JsonVo;
import com.shishuo.cms.service.DownPageService;

@Controller
@RequestMapping("/admin/downpage")
public class DownPageAction extends AdminBaseAction {
	@Autowired
	private DownPageService downPageService;
	@InitBinder("downPageEntity")
	public void initBinder(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("downPageEntity.");
	}

	@AuthPassport
	@RequestMapping(value = "/add.htm", method = RequestMethod.GET)
	public String addDownPageEntity(ModelMap modelMap) throws Exception {
		ClassesEntity classesEntity = new ClassesEntity();
		classesEntity.setType("down");
		List<ClassesEntity> classesList = classesService
				.getClassesByType(classesEntity);
		modelMap.put("classesList", classesList);
		return "system/downPage/add";
	}

	@AuthPassport
	@ResponseBody
	@RequestMapping(value = "/addNew.json", method = RequestMethod.POST)
	public JsonVo<String> addNewDownPage(DownPageEntity downPageEntity) throws Exception{
		JsonVo<String> json = new JsonVo<String>();
		if (validateJsonIsError(json))
			return json;
		downPageEntity.setStatus("1");
		downPageService.insert(downPageEntity);
		json.setResult(true);
		return json;
	}
	@AuthPassport
	@RequestMapping(value = "/page.htm", method = RequestMethod.GET)
	public String allList(
			@RequestParam(value = "p", defaultValue = "1") int pageNum,
			ModelMap modelMap) throws Exception {
		modelMap.put("pageVo", downPageService.getAllListPage(pageNum));
		return "system/downPage/all";
	}
	@AuthPassport
	@ResponseBody
	@RequestMapping(value = "/delete.json", method = RequestMethod.GET)
	public JsonVo<String> delete(
			@RequestParam(value = "id") long id) throws Exception {
		JsonVo<String> json = new JsonVo<String>();
		downPageService.deleteById(id);
		json.setResult(true);
		return json;
	}

	@RequestMapping(value = "/update.htm", method = RequestMethod.GET)
	public String update(@RequestParam(value = "id") long id,
			ModelMap modelMap, HttpServletRequest request) throws Exception {
		DownPageEntity downPageEntity=downPageService.getById(id);
		modelMap.put("downPageEntity", downPageEntity);
		ClassesEntity classesEntity = new ClassesEntity();
		classesEntity.setType("video");
		List<ClassesEntity> classesList = classesService
				.getClassesByType(classesEntity);
		modelMap.put("classesList", classesList);
		return "system/downPage/update";
	}
}
